<?php
// <copyright file="AuthenticationType.cs" company="NQtec">
// Copyright (c) 2008, 2009 All Right Reserved, http://www.dqer.com/
// Copyright (c) 2008, 2009 All Right Reserved, http://www.nqtec.com/
//
// This source is part of the DQER library that released under the LGPL.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Victor Gatkov</author>
// <email>v.gatkov@nqtec.com</email>
// <email>info@dqer.com</email>
// <date>2008-09-11</date>
// <summary>Contains a base, abstract class for an AuthorisationPolicyProvider</summary>

  // Todo -  squeeze img - wirlpll, HTML2RGB convert, include normal config! anti-hotlinking captcha prevent!!!!

define('PGID','captcha');           // set page name as PaGeID
define('PGTP','captcha');         // set page type as PaGeTyPe render/form/com/etc..
define('ROOT_PATH','../../../');        // may need to change path to site root from here
define('SRC_PATH',ROOT_PATH.'_');
define('IN_DQER_003311',true);

define('HDR_CONTYP','image/jpeg');
define('MOD_RECON',true); // use this to rearange incl mods
$mod_s['active'] = array('php','pgdt','style','hdr','session'); //mysql

require_once(SRC_PATH."/index.php");
// $len               = 5;
// $zz                = '';
//  for($i=0;$i<$len;$i++) $zz .= chr(rand(48,57));
 //  $session->set_xb($zz);

//  $code                          = $_SESSION['nac'];
  $code                          = $session->get_xb();

  $image_width                   = 140;
  $image_height                  = 30;
  $ttf_file                      = "./bedbug.ttf";
  $font_size                     = 16;
  $text_angle_minimum            = -20;    // minimum angle (in degress) of letter. counter-clockwise direction
  $text_angle_maximum            = 20;     // maximum angle (in degrees) of letter. clockwise direction
  $text_x_start                  = 10;     // position (in pixels) on the x axis where text starts
  $text_minimum_distance         = 13;     // the shortest distance in pixels letters can be from eachother
  $text_maximum_distance         = 30;     // the longest distance in pixels letters can be from eachother

//  purple/white
  $image_bg_color                = array("red" => 255, "green" => 255, "blue" => 255); // images background color
//  $text_color                    = array("red" => 139, "green" => 0, "blue" => 58); // the color of the text

//  blue/grey
//  $image_bg_color                = array("red" => 17, "green" => 17, "blue" => 17); // images background color
  $text_color                    = array("red" => 102, "green" => 102, "blue" => 204); // the color of the text

  $shkoi                         = 2;      // koi of shadow
  $shadow_text                   = TRUE;   // draw a shadow for the text (gives a 3d raised bolder effect)
  $use_transparent_text          = TRUE;   // true for the ability to use transparent text, false for normal text
  $text_transparency_percentage  = 65;     // 0 to 100, 0 being completely opaque, 100 being completely transparent
// ---------------------------------------------------------------------------------------
    if($use_transparent_text == TRUE) {
      $im = imagecreatetruecolor($image_width, $image_height);
      $bgcolor = imagecolorallocate($im, $image_bg_color['red'], $image_bg_color['green'], $image_bg_color['blue']);
      imagefilledrectangle($im, 0, 0, imagesx($im), imagesy($im), $bgcolor);
      $alpha = floor($text_transparency_percentage / 100 * 127);
      $font_color = imagecolorallocatealpha($im, $text_color['red'], $text_color['green'], $text_color['blue'], $alpha);
    } else { 
      $im = imagecreate($image_width, $image_height);
      $bgcolor = imagecolorallocate($im, $image_bg_color['red'], $image_bg_color['green'], $image_bg_color['blue']);
      $font_color = imagecolorallocate($im, $text_color['red'], $text_color['green'], $text_color['blue']);
    }

for($y=0;$y<$image_height;$y++){
 for($x=0;$x<$image_width;$x++){
     $e = rand(80,100);
     if ($e>=91) Imagesetpixel($im,$x,$y,$font_color);
     else Imagesetpixel($im,$x,$y,$bgcolor);
 }
}
    $x = $text_x_start;
    $code_len = strlen($code);
    $y_min = ($image_height / 2) + ($font_size / 2);
    $y_max = ($image_height / 2) + ($font_size / 2);

    for($i = 0; $i < $code_len; ++$i) {
      $angle = rand($text_angle_minimum, $text_angle_maximum);
      $y = rand($y_min, $y_max);
      imagettftext($im, $font_size, $angle, $x, $y, $font_color, $ttf_file, $code{$i});

      if($shadow_text == TRUE) {
        imagettftext($im, $font_size, $angle, $x + $shkoi, $y + $shkoi, $font_color, $ttf_file, $code{$i});
      }

      $x += rand($text_minimum_distance, $text_maximum_distance);
    }

    imagejpeg($im);
    imagedestroy($im);
?>
